<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="姓名">
              <a-input placeholder="请输入姓名" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>


          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>

    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,type:'radio'}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="leixing" slot-scope="text">
          <div v-for="i in text.split(',')" class="xiahuaxian">{{i}}</div>
        </template>
        <template slot="tel" slot-scope="text">
          <div v-for="i in text.split(',')" class="xiahuaxian">{{i}}</div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>



      </a-table>
    </div>

<!--    <formModal ref="modalForm" @ok="modalFormOk"></formModal>-->
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import {getAction,postAction} from '@api/manage'
  // import formModal from './formModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'

  export default {
    name: 'list',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      // formModal
    },

    data () {
      return {
        disableMixinCreated:true,
        description: '联系人选择模块',
        props: {
          customerId:{
            type: String,
            required: true
          }

        },
        // 表头

        columns: [
          /* {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          }, */
          {
            title:'姓名',
            align:"center",
            dataIndex: 'name'
          },
          {
            title:'类型',
            align:"center",
            dataIndex: 'leixing',
            scopedSlots: { customRender: 'leixing' }
          },
          {
            title:'电话',
            align:"center",
            dataIndex: 'tel',
            scopedSlots: { customRender: 'tel' }
          },

          /* {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          } */
        ],
        url: {
          list: "/sys/common/queryCustomerId",
          /* delete: "/contractorder/contractOrder/delete",
          deleteBatch: "/contractorder/contractOrder/deleteBatch",
          exportXlsUrl: "/contractorder/contractOrder/exportXls",
          importExcelUrl: "contractorder/contractOrder/importExcel", */

        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
      console.log('this.customerId=====LIST',this.customerId)
      /* this.url.list = "/sys/common/queryCustomerId?customerId="+this.customerId
      this.loadData() */
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    watch:{
      dataSource:{
        deep:true,
        handler(val){
          val.map(res=>{
            let arrPhone = []
            let arrType = []
            res.telephones.forEach(res1=>{
              arrPhone.push(res1.phone)
              arrType.push(res1.typeText)
            })
            res.tel = arrPhone.join(',')
            res.leixing = arrType.join(',')
            return res
          })
        }
      }
    },
    methods: {
      loadList(e){
        this.url.list = "/sys/common/queryCustomerId?customerId="+e
        this.loadData()
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'name',text:'姓名',dictCode:''})
        fieldList.push({type:'string',value:'leixing',text:'类型',dictCode:''})
        fieldList.push({type:'string',value:'tel',text:'电话',dictCode:''})
        this.superFieldList = fieldList
      },
      submitForm(){
        console.log(this.selectedRowKeys)
        let obj = this.dataSource.filter(res=>{
          if(this.selectedRowKeys.includes(res.id)){
            return res
          }
        })
        console.log(obj)
        this.$emit('ok',obj)
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
  .xiahuaxian{
    border-bottom: 1px solid #e9e9e9;
    padding: 4px 0;
  }
  .xiahuaxian:last-child{
    border-bottom: none;
  }
  /deep/ .j-table-force-nowrap .ant-table-selection-column{
    padding: 0 22px !important;
  }
</style>